package LeetCode.Stack;
import java.util.Stack;

/**
 * @Author:galaxy_yan
 * @Date: 2022/10/23
 * @Time: 15:49
 * @Description
 */
public class MinStack {
    Stack<Integer> stack;
    Stack<Integer> minstack;
    public MinStack() {
        stack=new Stack<>();
        minstack=new Stack<>();
        minstack.push(Integer.MAX_VALUE);
    }

    public void push(int val) {
        stack.push(val);
        minstack.push(Math.min(minstack.peek(), val));
    }

    public void pop() {
        if(stack.isEmpty()){
            return;
        }
        if(!minstack.isEmpty()&&stack.peek()==minstack.peek()){
            minstack.pop();
        }
        stack.pop();
    }


    public int top() {
        return stack.peek();
    }

    public int getMin() {
        return minstack.peek();
    }
}
